package models

import (
	"fmt"
)

type UserResponse struct {
	Id            int    `gorm:"primaryKey;autoIncrement" json:"id"`
	Name          string `gorm:"column:name" json:"name"`
	Account       string `gorm:"column:account" json:"account"`
	Password      string `gorm:"column:password" json:"password"`
	XueHao        string `gorm:"column:xue_hao" json:"xue_hao"`
	Position      string `gorm:"column:position" json:"position"`
	Sex           string `gorm:"sex" json:"sex"`
	Status        string `gorm:"status" json:"status"`
	Step          uint   `gorm:"step" json:"step"`
	Nation        string `gorm:"column:nation" json:"nation"`
	Birthday      string `gorm:"column:birthday" json:"birthday"`
	Origin        string `gorm:"column:origin" json:"origin"`
	Occupation    string `gorm:"column:occupation" json:"occupation"`
	IdentityId    string `gorm:"column:identity_id" json:"identity_id"`
	Education     string `gorm:"column:education" json:"education"` //学历
	Address       string `gorm:"column:address" json:"address"`
	Phone         string `gorm:"column:phone;type:varchar(11)" json:"phone"`
	Resume        string `gorm:"column:resume" json:"resume"`
	Organization  string `gorm:"column:organization" json:"organization"`
	Avatar        string `gorm:"column:avatar" json:"avatar"`
	Political     string `gorm:"column:political" json:"political"`
	PoliticalTime string `gorm:"column:political_time" json:"political_time"`
	Domicile      string `gorm:"column:domicile" json:"domicile"`
	College       string `gorm:"column:college" json:"college"`
	Class         string `gorm:"column:class" json:"class"`
	Major         string `gorm:"column:major" json:"major"`
	Enrollment    string `gorm:"column:enrollment" json:"enrollment"`
	BirthPlace    string `gorm:"column:birth_place" json:"birth_place"`
	Title         string `gorm:"column:title" json:"title"`
	Dorm          string `gorm:"column:dorm" json:"dorm"`     //宿舍
	Degree        string `gorm:"column:degree" json:"degree"` //学位
}
type User struct {
	Id            int    `gorm:"primaryKey;autoIncrement" json:"id"`
	Account       string `gorm:"column:account" json:"account"`
	Name          string `gorm:"column:name" json:"name"`
	Password      string `gorm:"column:password" json:"password"`
	XueHao        string `gorm:"column:xue_hao" json:"xue_hao"`
	Position      uint   `gorm:"column:position" json:"is_admin"`
	Sex           uint   `gorm:"sex" json:"sex"`
	Status        uint   `gorm:"status" json:"status"`
	Step          uint   `gorm:"step" json:"step"`
	Nation        string `gorm:"column:nation" json:"nation"`
	Birthday      string `gorm:"column:birthday" json:"birthday"`
	Origin        string `gorm:"column:origin" json:"origin"`
	Occupation    string `gorm:"column:occupation" json:"occupation"`
	IdentityId    string `gorm:"column:identity_id" json:"identity_id"`
	Education     string `gorm:"column:education" json:"education"`
	Address       string `gorm:"column:address" json:"address"`
	Phone         string `gorm:"column:phone;type:varchar(11)" json:"phone"`
	Resume        string `gorm:"column:resume" json:"resume"`
	Organization  uint   `gorm:"column:organization" json:"organization"`
	Avatar        string `gorm:"column:avatar" json:"avatar"`
	Political     string `gorm:"column:political" json:"political"`
	PoliticalTime string `gorm:"column:political_time" json:"political_time"`
	Domicile      string `gorm:"column:domicile" json:"domicile"`
	College       string `gorm:"column:college" json:"college"`
	Class         string `gorm:"column:class" json:"class"`
	Major         string `gorm:"column:major" json:"major"`
	Enrollment    string `gorm:"column:enrollment" json:"enrollment"`
	BirthPlace    string `gorm:"column:birth_place" json:"birth_place"` //出生地
	Title         string `gorm:"column:title" json:"title"`             //职称
	Dorm          string `gorm:"column:dorm" json:"dorm"`               //宿舍
	Degree        string `gorm:"column:degree" json:"degree"`           //学位
}

type Branch struct {
	Id       int    `json:"id"`
	Account  string `gorm:"column:account" json:"account"`
	Password string `gorm:"column:password" json:"password"`
	Name     string `gorm:"column:name" json:"name"`
}
type Committee struct {
	Id       int    `json:"id"`
	Account  string `gorm:"column:account" json:"account"`
	Password string `gorm:"column:password" json:"password"`
	Name     string `gorm:"column:name" json:"name"`
}

func (table *Branch) TableName() string {
	return "branches"
}
func (table *Committee) TableName() string {
	return "committees"
}
func (table *User) TableName() string {
	return "users"
}

func UsersToUserResponses(u []User) []UserResponse {
	fmt.Printf("%v", u)
	userResponses := make([]UserResponse, len(u))
	for i := 0; i < len(u); i++ {
		userResponses[i] = UserToUserResponse(u[i])
	}
	return userResponses
}
func UserToUserResponse(u User) UserResponse {
	userRep := UserResponse{
		Id:            u.Id,
		Name:          u.Name,
		Account:       u.Account,
		XueHao:        u.XueHao,
		Password:      u.Password,
		Position:      convertPosition(u.Position),
		Sex:           convertGender(u.Sex),
		Status:        convertStatus(u.Status),
		Step:          u.Step,
		Nation:        u.Nation,
		Birthday:      u.Birthday,
		Origin:        u.Origin,
		Occupation:    u.Occupation,
		IdentityId:    u.IdentityId,
		Education:     u.Education,
		Address:       u.Address,
		Phone:         u.Phone,
		Resume:        u.Resume,
		Organization:  convertOrganization(u.Organization),
		Avatar:        u.Avatar,
		PoliticalTime: u.PoliticalTime,
		Domicile:      u.Domicile,
		College:       u.College,
		Class:         u.Class,
		Major:         u.Major,
		Enrollment:    u.Enrollment,
		BirthPlace:    u.BirthPlace,
		Political:     u.Political,
		Title:         u.Title,
		Degree:        u.Degree,
	}
	return userRep
}
func UserResponseToUser(u UserResponse) User {
	user := User{
		Name: u.Name,
		//XueHao:       u.XueHao,
		Account:       u.Account,
		Position:      InvertedPositionMap[u.Position],
		Sex:           InvertedGenderMap[u.Sex],
		Status:        InvertedStatusMap[u.Status],
		Nation:        u.Nation,
		Birthday:      u.Birthday,
		Origin:        u.Origin,
		Occupation:    u.Occupation,
		IdentityId:    u.IdentityId,
		Education:     u.Education,
		Address:       u.Address,
		Phone:         u.Phone,
		Resume:        u.Resume,
		Organization:  InvertedOrganizationMap[u.Organization],
		PoliticalTime: u.PoliticalTime,
		Avatar:        u.Avatar,
		Domicile:      u.Domicile,
		College:       u.College,
		Class:         u.Class,
		Major:         u.Major,
		Enrollment:    u.Enrollment,
		BirthPlace:    u.BirthPlace,
		Political:     u.Political,
		Title:         u.Title,
		Degree:        u.Degree,
	}
	return user
}

var GenderMap = map[uint]string{
	1: "男",
	0: "女",
}
var PositionMap = map[uint]string{
	0: "学生",
	1: "教师",
}
var statusMap = map[uint]string{
	1: "入党申请",
	2: "入党积极分子的确定和培养教育",
	3: "发展对象的确定和考察",
	4: "预备党员的接收",
	5: "预备党员的教育考察和转正",
}
var OrganizationMap = map[uint]string{
	0: "人工智能学院本科生第一党支部",
	1: "人工智能学院本科生第二党支部",
	2: "人工智能学院教工党支部",
	3: "人工智能学院研究生党支部",
}
var InvertedGenderMap = map[string]uint{
	"男": 1,
	"女": 0,
}
var InvertedPositionMap = map[string]uint{
	"学生": 0,
	"教师": 1,
}
var InvertedStatusMap = map[string]uint{
	"入党申请": 0,
	"入党积极分子的确定和培养教育": 1,
	"发展对象的确定和考察":     2,
	"预备党员的接收":        3,
	"预备党员的教育考察和转正":   4,
}
var InvertedOrganizationMap = map[string]uint{
	"人工智能学院本科生第一党支部": 0,
	"人工智能学院本科生第二党支部": 1,
	"人工智能学院教工党支部":    2,
	"人工智能学院研究生党支部":   3,
}

func convertOrganization(o uint) string {
	if val, ok := OrganizationMap[o]; ok {
		return val
	}
	return "未知"
}
func convertGender(gender uint) string {
	if val, ok := GenderMap[gender]; ok {
		return val
	}
	return "未知"
}
func convertPosition(p uint) string {
	if val, ok := PositionMap[p]; ok {
		return val
	}
	return "未知"
}
func convertStatus(s uint) string {
	if val, ok := statusMap[s]; ok {
		return val
	}
	return "未知"
}

//	type UserStatus struct {
//		Name       string    `gorm:"column:name" json:"name"`
//		Sex        string    `gorm:"sex" json:"sex"`
//		Nation     string    `gorm:"column:nation" json:"nation"`
//		Birthday   time.Time `gorm:"column:birthday" json:"birthday"`
//		Origin     string    `gorm:"column:origin" json:"origin"`
//		IdentityId string    `gorm:"column:identity_id" json:"identity_id"`
//		Occupation string    `gorm:"column:occupation" json:"occupation"`
//		Education  string    `gorm:"column:education" json:"education"`
//		Phone      string    `gorm:"column:phone;" json:"phone"`
//		Address    string    `gorm:"column:address" json:"address"`
//		Status     string    `gorm:"status" json:"status"`
//		Step       uint      `gorm:"step" json:"step"`
//	}
type UserStatus struct {
	Name       string `gorm:"column:name" json:"name"`
	Sex        int    `gorm:"sex" json:"sex"`
	Nation     string `gorm:"column:nation" json:"nation"`
	Birthday   string `gorm:"column:birthday" json:"birthday"`
	Origin     string `gorm:"column:origin" json:"origin"`
	IdentityId string `gorm:"column:identity_id" json:"identity_id"`
	Occupation string `gorm:"column:occupation" json:"occupation"`
	Education  string `gorm:"column:education" json:"education"`
	Phone      string `gorm:"column:phone;" json:"phone"`
	Address    string `gorm:"column:address" json:"address"`
	Status     uint   `gorm:"status" json:"status"`
	Step       uint   `gorm:"step" json:"step"`
	Avatar     string `gorm:"column:avatar" json:"avatar"`
}
type Data struct {
	Title         string `json:"title"`
	StateCartData []Steps
}
type Steps struct {
	TopText    string `gorm:"column:top_text" json:"top_text"`
	StepId     uint   `gorm:"column:step_id" json:"step_id"`
	MiddleText string `gorm:"column:middle_text" json:"middle_text"`
	BottomText string `gorm:"column:bottom_text" json:"bottom_text"`
}
